package com.online.dao.user.Impl;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class BaseDao {
    private final static String driver;
    private final static String url;
    private final static String username;
    private final static String pwd;

    static {
        Properties properties = new Properties();
        InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
        try {
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        driver = properties.getProperty("driver");
        url = properties.getProperty("url");
        username = properties.getProperty("username");
        pwd = properties.getProperty("pwd");
    }
    //获取数据库链接
    public static Connection getConnection(){
        Connection connection = null;
        try {
            Class.forName(driver);
         connection = DriverManager.getConnection(url,username,pwd);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
                e.printStackTrace();
        }
        return connection;
    }

}
